package se.sll.itintegration.catalogue.gui.service.view.capacity;

import java.util.ArrayList;
import java.util.List;

import se.sll.service.catalogue.common.Translator;
import se.sll.service.catalogue.common.rest.request.CapacityCreateRequest;

public class CapacityCreateRequestListUnitTranslator implements Translator<CapacityViewUnit, List<CapacityCreateRequest>> {
    private static final CapacityCreateRequestListUnitTranslator INSTANCE = new CapacityCreateRequestListUnitTranslator();

    private CapacityCreateRequestListUnitTranslator() {
    }

    @Override
    public List<CapacityCreateRequest> translate(CapacityViewUnit from) {
        return translateTo(from, new ArrayList<CapacityCreateRequest>());
    }

    @Override
    public List<CapacityCreateRequest> translateTo(CapacityViewUnit from, List<CapacityCreateRequest> to) {
        String hsaID = from.getHsaID();
        CapacityCreateRequestListProductTranslator translator = new CapacityCreateRequestListProductTranslator(hsaID);
        List<CapacityViewProduct> products = from.getProducts();
        for (CapacityViewProduct product : products) {
            translator.translateTo(product, to);
        }
        return to;
    }

    public static CapacityCreateRequestListUnitTranslator getInstance() {
        return INSTANCE;
    }
}
